#include "file.h"


//写到1.txt文件中
void xieFile(Node* list){
    FILE* fp =fopen("1.txt","w");
    if(NULL==fp){
        printf("文件打开失败！\n");
        return;
    }
    //printf("1\n");
    Node* t=list;
   int i;
    while(t){
        fwrite(&(t->s),1,sizeof (Stu),fp);
        i++;   
        t=t->pNext;
     
    }
    printf("%d",i);
    fclose(fp);
    printf("写入成功！\n");
}

//读到链表中
void duFile(Node** list){
    FILE* fp =fopen("1.txt","r");
    if(NULL==fp){
        printf("文件打开失败！\n");
        return;
    }
    int r;
    //int n;
    Stu temp;//临时存储文件中读出的学生结构体
    while(1){
        r = fread(&temp,1,sizeof(Stu),fp);
        //printf("2\n");
        if(r<=0) break;
        add(list,temp);
      //  n++;
    }
    //printf("%d",n);
    fclose(fp);
    //showall(*list);
    
    printf("读出成功！\n");
}
